﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace Pomodoro
{
    // Fonts Windows Phone: http://msdn.microsoft.com/en-us/library/ff806365(v=vs.95).aspx
    // Fonts Silverlight:   http://msdn.microsoft.com/en-us/library/cc189010(v=vs.95).aspx
    // Bug Soegoe WP Bold: http://forums.create.msdn.com/forums/t/95660.aspx

    public class TimeScale
    {
        private Canvas _canvas;
        private int _height;
        private int _offsetx;
        private int _space;
        private int _minutes;

        public TimeScale(Canvas canvas, int height, int offsetx, int space, int minutes)
        {
            _canvas = canvas;
            _height = height;
            _offsetx = offsetx;
            _space = space;
            _minutes = minutes;
            Draw();
        }

        private void Draw()
        {
            var font = new FontFamily("Segoe WP Semibold");
            var brush = new SolidColorBrush(Colors.White);

            _canvas.Children.Clear();
            _canvas.Width = (_offsetx * 2) + (_minutes * _space);

            for (int minute = 0; minute < _minutes + 1; minute++)
            {
                bool isFive = ((minute % 5) == 0);

                var line = new Line();
                line.X1 = line.X2 = _offsetx + (_space * minute);
                line.Y1 = _height - (isFive ? 40 : 10);
                line.Y2 = _height;
                line.Stroke = brush;
                line.StrokeThickness = isFive ? 4 : 2;
                _canvas.Children.Add(line);

                if (isFive)
                {
                    var caption = new TextBlock();
                    caption.Text = minute.ToString();
                    caption.FontFamily = font;
                    caption.FontSize = 24;
                    caption.TextAlignment = TextAlignment.Center;
                    caption.Foreground = brush;

                    var panel = new StackPanel();
                    panel.Width = 30;
                    panel.Children.Add(caption);

                    panel.SetValue(Canvas.TopProperty, line.Y1 - 40);
                    panel.SetValue(Canvas.LeftProperty, line.X1 - 15);
                    _canvas.Children.Add(panel);

                }
            }
        }

        
    }
}
